package com.jader.adapter;

import java.util.ArrayList;
import java.util.List;

import com.jader.beans.LunTan_All_Bens;
import com.jader.util.JaderApplication;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.http.RequestParams;
import com.zlp.jader.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter_ALL extends BaseAdapter {
	// 通过构造器获取数据来源
	public List<LunTan_All_Bens> list = new ArrayList<LunTan_All_Bens>();
	// 接收上下文参数，以便了解是哪个activity在调用
	Context context;
	// 用来初始化布局文件，可以把一个xml布局转换为对应的android对象view
	LayoutInflater mInflater;
	// ViewHolder viewHolder;
	private BitmapUtils bitmapUtils;
	RequestParams params;
	private String url = JaderApplication.getIP();

	public MyAdapter_ALL(List<LunTan_All_Bens> list, Context context) {
		super();
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(context);
		bitmapUtils = JaderApplication.getBitmapUtils();
		bitmapUtils.configDefaultLoadingImage(R.drawable.pic_item_list_default);
	}

	public void onDateChange(List<LunTan_All_Bens> list) {
		this.list = list;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// 数据总量
		return list.size();
	}

	public List<LunTan_All_Bens> getList() {
		return list;
	}

	public void setList(List<LunTan_All_Bens> list) {
		this.list = list;
	}

	@Override
	public Object getItem(int position) {
		// 返回每一行的数据
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// 返回每一行的id，几乎很少用到，列表的索引号，从零开始
		return position;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(R.layout.item_luntan_allfragment, null);

		ImageView headiImageView = (ImageView) convertView
				.findViewById(R.id.item_luntan_suoyou_imageview);

		TextView userNameTextView = (TextView) convertView
				.findViewById(R.id.item_luntan_suoyou_nameText);

		TextView timeTextView = (TextView) convertView
				.findViewById(R.id.item_luntan_suoyou_timeText);
		TextView themeTextView = (TextView) convertView
				.findViewById(R.id.item_luntan_suoyou_biaotiText);

		ImageView goodsImageView1 = (ImageView) convertView
				.findViewById(R.id.item_luntan_suoyou_zhanshiimageview);
		ImageView goodsImageView2 = (ImageView) convertView
				.findViewById(R.id.item_luntan_suoyou_zhanshiimageview1);
		ImageView goodsImageView3 = (ImageView) convertView
				.findViewById(R.id.item_luntan_suoyou_zhanshiimageview2);

		//final TextView praiseNumbertTextView = (TextView) convertView
		//		.findViewById(R.id.zan_Number_Text);
		String redID = list.get(position).getUserBens().getPicture();
		bitmapUtils.display(headiImageView, JaderApplication.getIP()+"/Jader"+redID);
		List<String> list_url = list.get(position).getList();

		if (list_url == null||list_url.size()==0) {
			
		}
		/*if (list_url != null && list.get(position).getList().get(0)
				.equals("/Jader/image/tiezi/20151103200032472.png")) {
		  goodsImageView1.setVisibility(View.GONE);
		  goodsImageView2.setVisibility(View.GONE);
		  goodsImageView3.setVisibility(View.GONE);
		
		}*/

		if (list_url != null && list_url.size() == 1) {
			bitmapUtils.display(goodsImageView1, url
					+ list.get(position).getList().get(0));
			Log.e("tupianlujing", url+ list.get(position).getList().get(0));
		}
		if (list_url != null && list_url.size() == 2) {
			bitmapUtils.display(goodsImageView1, url
					+ list.get(position).getList().get(0));
			bitmapUtils.display(goodsImageView2, url
					+ list.get(position).getList().get(1));
		}

		if (list_url != null && list_url.size() > 2) {
			bitmapUtils.display(goodsImageView1, url
					+ list.get(position).getList().get(0));
			bitmapUtils.display(goodsImageView2, url
					+ list.get(position).getList().get(1));
			bitmapUtils.display(goodsImageView3, url
					+ list.get(position).getList().get(2));
		}
		//final int pra = list.get(position).getPraiseNumber();
		//praiseNumbertTextView.setText(pra + "");

		final String text = list.get(position).getUserBens().getUsername();
		userNameTextView.setText(text);

		final String text1 = list.get(position).getTheme();
		themeTextView.setText(text1);

		final String date = list.get(position).getDate();
		timeTextView.setText(date);

		return convertView;

	}
}